package com.ruoyi.cs.event.customerEvent.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cs.event.customerEvent.domain.CustomerEvent;
import com.ruoyi.cs.event.customerEvent.domain.CustomerEventCond;
import com.ruoyi.cs.event.customerEvent.service.ICustomerEventService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 客户事件
 */
@RestController
@RequestMapping("/cs/event")
@Api(value = "客户事件模块", tags = "客户事件接口")
public class CustomerEventController extends BaseController {
    @Autowired
    private ICustomerEventService customerEventService;
    /**
     * 获取客户事件
     * @param cond
     * @return
     */
    @ApiOperation(value = "获取客户事件",notes = "查询所有客户事件信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CustomerEventCond cond){
        startPage();
        List<CustomerEvent> customerEventList = customerEventService.selectCustomerEventList(cond);
        return getDataTable(customerEventList);
    }

    /**
     * 导出客户事件
     * @param cond
     * @return
     */
    @ApiOperation(value = "导出客户事件",notes = "导出客户事件")
    @PostMapping("/export")
    public AjaxResult export(@RequestBody CustomerEventCond cond)
    {
        List<CustomerEvent> customerEventList = customerEventService.selectCustomerEventList(cond);
        ExcelUtil<CustomerEvent> util = new ExcelUtil<>(CustomerEvent.class);
        return util.exportExcel(customerEventList, "客户事件数据");
    }

    /**
     * 新增客户事件
     * @param customerEvent
     * @return
     */
    @ApiOperation(value = "新增客户事件", notes = "新增客户事件")
    @ApiImplicitParam(name = "customerEvent", value = "新增客户事件", dataType = "CustomerEvent")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CustomerEvent customerEvent){

        return toAjax(customerEventService.insertCustomerEvent(customerEvent));
    }

    /**
     * 修改客户事件
     * @param customerEvent
     * @return
     */
    @ApiOperation(value = "修改客户事件", notes = "修改客户事件")
    @ApiImplicitParam(name = "customerEvent", value = "修改客户事件", dataType = "CustomerEvent")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody CustomerEvent customerEvent)
    {
        return toAjax(customerEventService.updateCustomerEvent(customerEvent));
    }

    /**
     * 删除客户事件
     * 仅修改删除标志位
     * @param customerEvent
     * @return
     */
    @ApiOperation(value = "删除客户事件", notes = "删除客户事件")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody CustomerEvent customerEvent)
    {

        return toAjax(customerEventService.updateCustomerEventDeleteFlag(customerEvent));
    }
}
